package com.springcloud.demo.test.schedule;

import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;


/**
 * @author zhouyang
 * @Description
 * @date 2018/11/24
 */
@Configuration
public class Config implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    private QuartzScheduler quartzScheduler;
    @Autowired
    private Scheduler scheduler;

    /**
     * 初始启动quartz
     */
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        try {
            quartzScheduler.startJob();
            quartzScheduler.addJob(scheduler, 3, "z");
            quartzScheduler.addJob(scheduler, 5, "y");
            quartzScheduler.modifyJob("z", "z", 50);
            System.out.println("任务已经启动...");
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }



}



